#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <cerrno>
#include <cstring>
#include <unistd.h>
#include <cstdlib>
#include <fcntl.h>

using namespace std;

#define Mode 0666
#define Path "./default"


class Fifo
{
public:
    Fifo(string path = Path, int mode = Mode)
        :_path(path)
        ,_mode(mode)
    {}

    void CreateNamePipe()
    {
        int return_mkfifo_val = mkfifo(_path.c_str(),_mode);
        if(return_mkfifo_val < 0)
        {
            cout << "mkfifo error:" << errno << " reason :" << strerror(errno) << endl;
            exit(1);
        }

        cout << "mkfifo success" << endl;
    }

    ~Fifo()
    {
        int return_unlink_val = unlink(_path.c_str());
        if(return_unlink_val < 0)
        {
            cout << "unlink error:" << errno << " reason :" << strerror(errno) << endl;
        }

        cout << "unlink namepipe success" << endl;
    }

private:
    string _path;
    int _mode;

};


